
Page({
  data: {
    artists: [],
    page: 1,
    size: 20
  },
  toDetail(event) {
    // console.log(event.target.dataset)
    wx.navigateTo({
      // 跨页面传递参数
      url: './detail?aid=' + event.target.dataset.aid
    })
  },
  onLoad(options) {
    const self = this
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      method: 'GET',
      // url: 'https://music.qier222.com/api/search?keywords=赵本山',
      url: `https://music.qier222.com/api/top/artists?offset=${(this.data.page - 1) * this.data.size}&limit=${this.data.size}`,
      success(res) {
        self.setData({
          artists: res.data.artists
        })
      },
      complete() {
        wx.hideLoading()
      }
    })
  },
  onPullDownRefresh() {

  },
  // .json    onReachBottomDistance
  onReachBottom() {
    const self = this
    console.log("加载下一页")

    // 页码加一
    this.setData({
      page: this.data.page + 1
    })
    // 请求下一页数据
    wx.showNavigationBarLoading()
    wx.request({
      method: 'GET',
      url: `https://music.qier222.com/api/top/artists?offset=${(this.data.page - 1) * this.data.size}&limit=${this.data.size}`,
      success(res) {
        console.log(res.data)
        self.setData({
          // artists: self.data.artists.concat(res.data.artists)
          artists: [...self.data.artists, ...res.data.artists]
        })
      },
      complete() {
        wx.hideNavigationBarLoading()
      }
    })
  },
})